package club.pinea.session;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 全局session容器
 */
public class GlobalSessionContainer {
    private static ConcurrentHashMap<Integer, IOSession> playerMap = new ConcurrentHashMap<Integer, IOSession>();

    public static void addIOSession(IOSession session) {
        playerMap.put(session.getSessionId(), session);
    }

    public static int getIOSessionSize() {
        return playerMap.size();
    }

    public static IOSession getIOSession(int sessionId) {
        return playerMap.get(sessionId);
    }

    public static void delIOSession(IOSession session) {
        if (session != null) {
            playerMap.remove(session.getSessionId());
        }
    }

    public static void delIOSession(Integer sessionId) {
        if (sessionId != null) {
            playerMap.remove(sessionId);
        }
    }
}
